package com.test.util;

import java.util.Arrays;
import java.util.List;

/**
 * 软分页. <br>
 * 软分页类.
 * <p>
 * Copyright: Copyright (c) Dec 1, 2010 4:39:49 PM
 * <p>
 * Company: 北京宽连十方数字技术有限公司
 * <p>
 * 
 * @author suncg@c-platform.com
 * @version 1.0.0
 */
public class SoftPagination {

	private int pageSize = 0;

	private int currentPage = 1;

	String pageMark = StringUtils.EMPTY;

	String content = StringUtils.EMPTY;

	private List<String> contentList = null;

	public SoftPagination(String pageMark, String content, int currentPage) {
		this.pageMark = pageMark;
		this.content = content;
		this.currentPage = currentPage;
		String[] contentArray = StringUtils.split(content, pageMark);
		contentList = Arrays.asList(contentArray);
		this.pageSize = contentArray.length;
	}

	public int nextPage() {
		if (currentPage + 1 > pageSize)
			return pageSize;
		else {
			return currentPage + 1;
		}
	}

	public int previousPage() {
		if (currentPage - 1 < 0) {
			return pageSize;
		} else {
			return currentPage - 1;
		}
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public String getPageContent(int page) {
		page = page - 1;
		if (page > pageSize)
			return StringUtils.EMPTY;
		else if (page < 0)
			return StringUtils.EMPTY;
		else
			return contentList.get(page);
	}

	public int getPageSize() {
		return pageSize;
	}

}
